<!--
1. 要给列表添加动画，需要使用 transition-group 标签
2. .v-move 可以让列表删除元素时过渡自然
3. .appear 可以给列表本身添加动画。
-->




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../lib/vue.js"></script>
    <style>
        .v-enter, .v-leave-to{
            opacity: 0;
            transform:translateX(80px);
        }
        .v-enter-active, .v-leave-active{
            transition: all 0.4s ease;
            position: absolute;
        }
        .v-move{
            transition: all 0.4s ease;
        }
    </style>


</head>
<body>
    <div id="app">
        Id:
        <input type="text" v-model="id">
        Name:
        <input type="text" v-model="name">
        <button @click="add">增加</button>
        <transition-group appear>
            <li v-for="(item,i) in list" :key="item.id" @click="del(i)">
                {{item.id}}---{{item.name}}
            </li>
        </transition-group>
    </div>
    <script>
        var vm=new Vue({
            el:"#app",
            data:{
                id:'',
                name:'',
                list:[
                    {id:1,name:"李世民"},
                    {id:2,name:"朱元璋"},
                    {id:3,name:"刘邦"},
                    {id:4,name:"毛泽东"}
                ]
            },
            methods:{
                add(){
                    this.list.push({id:this.id,name:this.name});
                },
                del(i){
                    this.list.splice(i,1);
                }
            }
        })
    </script>
</body>
</html>